package com.moonciki.artadmin.web.controller.game;

import com.moonciki.artadmin.common.annotation.Log;
import com.moonciki.artadmin.common.enums.BusinessType;
import com.moonciki.artadmin.core.base.BaseController;
import com.moonciki.artadmin.core.model.FileWrapper;
import com.moonciki.artadmin.core.model.PageData;
import com.moonciki.artadmin.core.model.PageParameter;
import com.moonciki.artadmin.core.model.WebResult;
import com.moonciki.artadmin.web.mybatis.entity.fuzhu.FzGame;
import com.moonciki.artadmin.web.service.game.IFzGameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 游戏列Controller
 *
 * @author ruoyi
 * @date 2022-02-16
 */
@Api(tags = "游戏列接口")
@RestController
@RequestMapping("/fuzhu/game")
public class FzGameController extends BaseController {

    @Autowired
    private IFzGameService fzGameService;

    @ApiOperation(value = "查询游戏列列表")
    @PreAuthorize("@ss.hasPermi('fuzhu:game:list')")
    @GetMapping("/list")
    public WebResult<PageData<FzGame>> list(PageParameter pageParameter, FzGame fzGame) {
        PageData<FzGame> pageData = fzGameService.getPageList(pageParameter, fzGame);
        WebResult<PageData<FzGame>> result = WebResult.successResponse(pageData);
        return result;
    }

    @ApiOperation(value = "导出游戏列列表")
    @PreAuthorize("@ss.hasPermi('fuzhu:game:export')")
    @Log(title = "游戏列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FzGame fzGame) {
        FileWrapper fileWrapper = fzGameService.export(fzGame);

        super.responseFile(response, fileWrapper);
    }

    @ApiOperation(value = "获取游戏列详细信息")
    @PreAuthorize("@ss.hasPermi('fuzhu:game:detail')")
    @GetMapping(value = "/detail")
    public WebResult<FzGame> detail(Long id) {
        FzGame fzGame = fzGameService.getById(id);
        return WebResult.successResponse(fzGame);
    }

    @ApiOperation(value = "新增游戏列")
    @PreAuthorize("@ss.hasPermi('fuzhu:game:add')")
    @Log(title = "游戏列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public WebResult<FzGame> add(@RequestBody FzGame fzGame) {
        FzGame insert = fzGameService.insertFzGame(fzGame);
        return WebResult.successResponse(insert);
    }

    @ApiOperation(value = "修改游戏列")
    @PreAuthorize("@ss.hasPermi('fuzhu:game:edit')")
    @Log(title = "游戏列", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public WebResult<Integer> edit(@RequestBody FzGame fzGame) {
        int edit = fzGameService.updateFzGame(fzGame);
        return WebResult.successResponse(edit);
    }

    @ApiOperation(value = "删除游戏列")
    @PreAuthorize("@ss.hasPermi('fuzhu:game:remove')")
    @Log(title = "游戏列", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete")
    public WebResult<Integer> remove(@RequestBody List<Long> idList) {
        int i = fzGameService.deleteByIds(idList);
        return WebResult.successResponse(i);
    }

}
